<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="x-ua-compatible" content="ie=edge">
		<title></title>
		<meta name="description" content="Neat">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" user-scalable="no">
		<link rel="stylesheet" href="index.css">
		<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
		<script src="https://www.jq22.com/demo/sweetalert-master-150108224250/lib/sweet-alert.js"></script>
		<link rel="stylesheet" href="https://www.jq22.com/demo/sweetalert-master-150108224250/lib/sweet-alert.css">
		<script src="https://www.jq22.com/demo/copy20161120/dist/clipboard.min.js"></script>
		<style>
			.form-group .text-input {
				text-indent: 10px
			}

			.items-group .item .icon {
				color: red;
				border-color: red
			}

			.items-group .item .icon:hover {
				background-color: red;
				color: white
			}
		</style>
	</head>
	<body>

		<div class="main-group">
			<h1 style="font-size: 28px;text-align: center;">通知确认</h1>
			<div class="form-group">

			</div>
			<div>
				<div class="items-group" id="nos">
				</div>
			</div>
			<div class="btn-group">
				<button class="del-btn" onclick="set()"></button>
			</div>

			<div class="icon success animate" style="display: block;"> <span class="line tip animateSuccessTip"></span>
				<span class="line long animateSuccessLong"></span>
				<div class="placeholder"></div>
				<div class="fix"></div>
			</div>
		</div>
	</body>
</html>
<script type="text/javascript">
	let noteid = queryURLParams(location.href).id
	let s = 5
	$(document).ready(function() {
		if (!localStorage.getItem("bpaName")) {
			setTimeout(() => {
				swal({
					title: "未绑定",
					type: "error",
					text: "请在群内报平安登记页面绑定后再确认消息",
					confirmButtonText: "好的"
				})
			}, 10)
			$(".btn-group").hide()
		}
		$("#nos")[0].style.maxHeight = "100%"
		$.get(`https://39.107.221.29/studentBpa/getNote.php?id=${noteid}`,
			function(data, status) {
				data = JSON.parse(data)
				console.log(data)
				$("#nos").html(data.message)
				timerinit()
			})
	})

	function queryURLParams(url) {
		let pattern = /(\w+)=(\w+)/ig; //定义正则表达式
		let parames = {}; // 定义参数对象
		url.replace(pattern, ($, $1, $2) => {
			parames[$1] = $2;
		});
		return parames;

	}

	function set() {
		if (s !== 0) {
			return
		}
		$.get(`https://39.107.221.29/studentBpa/addNote.php?noteid=${noteid}&classnum=${localStorage.getItem("bpaClassNum")}&num=${localStorage.getItem("bpaNum")}`,
			function(data,
				status) {
				if (data == "") {
					swal({
						title: " 查询失败",
						type: "error",
						text: "我也不知道为什么",
						confirmButtonText: "好的"
					});
				} else {
					data = JSON.parse(data)
					console.log(data)
					if (data.code == 200) {
						swal({
							title: " 成功",
							type: "success",
							text: "你已确认该通知",
							confirmButtonText: "好的"
						});
					} else {
						swal({
							title: " 失败",
							type: "error",
							text: data.msg,
							confirmButtonText: "好的"
						});
					}
				}
			})
		// alert("数据: " + data + "\n状态: " + status);
	}

	function timerinit() {
		let timer = setInterval(
			() => {
				if (s == 0) {
					$(".del-btn").html("我已阅读，确认收到通知")
					clearInterval(timer)
					return
				}
				$(".del-btn").html("请阅读通知，" + s + "秒后可进行确认")
				s--
			}, 1000)
	}
</script>
